package com.ruoyi.canteen.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.canteen.domain.CanteenOrderAddress;
import com.ruoyi.canteen.service.ICanteenOrderAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订餐地址Controller
 * 
 * @author zhangw
 * @date 2021-09-19
 */
@RestController
@RequestMapping("/canteen/orderAddress")
public class CanteenOrderAddressController extends BaseController
{
    @Autowired
    private ICanteenOrderAddressService canteenOrderAddressService;

    /**
     * 查询订餐地址列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:orderAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(CanteenOrderAddress canteenOrderAddress)
    {
        startPage();
        List<CanteenOrderAddress> list = canteenOrderAddressService.selectCanteenOrderAddressList(canteenOrderAddress);
        return getDataTable(list);
    }

    /**
     * 导出订餐地址列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:orderAddress:export')")
    @Log(title = "订餐地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CanteenOrderAddress canteenOrderAddress)
    {
        List<CanteenOrderAddress> list = canteenOrderAddressService.selectCanteenOrderAddressList(canteenOrderAddress);
        ExcelUtil<CanteenOrderAddress> util = new ExcelUtil<CanteenOrderAddress>(CanteenOrderAddress.class);
        return util.exportExcel(list, "订餐地址数据");
    }

    /**
     * 获取订餐地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('canteen:orderAddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(canteenOrderAddressService.selectCanteenOrderAddressById(id));
    }

    /**
     * 新增订餐地址
     */
    @PreAuthorize("@ss.hasPermi('canteen:orderAddress:add')")
    @Log(title = "订餐地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CanteenOrderAddress canteenOrderAddress)
    {
        return toAjax(canteenOrderAddressService.insertCanteenOrderAddress(canteenOrderAddress));
    }

    /**
     * 修改订餐地址
     */
    @PreAuthorize("@ss.hasPermi('canteen:orderAddress:edit')")
    @Log(title = "订餐地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CanteenOrderAddress canteenOrderAddress)
    {
        return toAjax(canteenOrderAddressService.updateCanteenOrderAddress(canteenOrderAddress));
    }

    /**
     * 删除订餐地址
     */
    @PreAuthorize("@ss.hasPermi('canteen:orderAddress:remove')")
    @Log(title = "订餐地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(canteenOrderAddressService.deleteCanteenOrderAddressByIds(ids));
    }
}
